﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Permission.Interface;
using Micrhard.FMCG.Server.DataAccess;
using Microhard.Permission.Models;
using Microhard.Core.DBUtility;

namespace Micrhard.FMCG.Server.Impl
{
    public class EmployeeInfoOnLogonValidator : IEmployeeValidator
    {
        public EmpInfoModel IsExistEmployee(string userName)
        {
            EmpInfoModel eim = new EmpInfoModel();
            MicrhardFMCGServerEntities db = new MicrhardFMCGServerEntities();
            var emp = db.Employees.SingleOrDefault(e => e.UserName == userName);
            if (emp != null)
            {
                eim.CompanyID = emp.CompanyID.Value;
                eim.CompanyName = emp.Company.Name;
                eim.CompanyRange = emp.Range.Value;
                eim.EmployeeName = emp.Name;
                eim.UserName = emp.UserName;
                eim.EmployeeID = emp.EmployeeID;
            }
            return eim;
        }
    }
}
